﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class admin_tzgl_sctz : System.Web.UI.Page
{
    NoticeBT nt = new NoticeBT();
    AdminBT adm = new AdminBT();
    public int pagesize = 10;
    public int pages = 0;
    public int page = 1;
    public int prePage = 1;
    public int forPage = 1;
    public int dataTotal = 0;
    public string page_url;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin_id"] == null)
        {
            Response.Redirect("admin_logout.aspx");
            return;
        }
        if (!IsPostBack)
        {
            if (Request["page"] != null)
            {
                string p = Request["page"];
                page = int.Parse(p);
            }
            else
            {
                page = 1;
            }
            ViewState.Add("page", page);
            page_url = Request.Url.ToString().Split('?')[0];
            controlRepeater();
        }
    }

    private void controlRepeater()
    {
        if (ViewState["page"] != null)
        {
            page = (int)ViewState["page"];
        }
        DataTable tabel1 = nt.GetAllNotice();
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = tabel1.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = pagesize;
        pages = pds.PageCount;
        dataTotal = tabel1.Rows.Count;
        pds.CurrentPageIndex = page - 1;
        page = page < 1 ? 1 : page;
        page = page > pages ? pages : page;
        prePage = page - 1;
        forPage = page + 1;
        pds.CurrentPageIndex = page - 1;
        
        this.repeater1.DataSource = pds;
        this.repeater1.DataBind();
    }

    protected void btDelete_Click(object sender, EventArgs e)
    {
        LinkButton lb = (LinkButton)sender;
        int id = Int32.Parse(lb.CommandName.ToString());
        deleteNotice(id);

    }

    public void deleteNotice(int id)
    {
        bool del = nt.delNotice(id);
        if (del)
        {
            this.lbMsg.Text = "删除成功";
            this.controlRepeater();
        }
        else 
        {
            this.lbMsg.Text = "删除失败";
        }
    }
    public string checkemergency(bool emergency) 
    {
        if (emergency)
        {
            return "重要";
        }
        else 
        {
            return "普通";
        }
    }

    public string getAdminname(int adminId)
    {
        AdminBT adm = new AdminBT();
        return adm.FindbyId(adminId);
    }

    protected void btDelAll_Click(object sender, EventArgs e)
    {
        bool del = nt.delAllNotice();
        if (del)
        {
            this.lbMsg.Text = "全部删除成功";
            this.controlRepeater();
        }
        else
        {
            this.lbMsg.Text = "删除失败";
        }
    }
}
